package cn.ruc.dbiir.warn.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.ruc.dbiir.warn.adapter.DataSourceAdapter;
import cn.ruc.dbiir.warn.utils.Config;
import cn.ruc.dbiir.warn.utils.DBUtil;
import cn.ruc.dbiir.warn.utils.NotificationUtil;
import cn.ruc.dbiir.warn.utils.ParseUtil;

@Controller
@RequestMapping(value = "/highEchart")
public class HignChartsController
{
	/**
	 * 数据源切换API
	 * author：mark   
	 * createTime：Dec 9, 2019 12:00:48 AM
	 * @param type
	 * @return
	 */
	//http://localhost:8080/warn/highEchart/setDataSource?type=1
	@RequestMapping(value = "/setDataSource")
	@ResponseBody
	public Object setDataSource(@RequestParam(value = "type") int type)
	{
		Config.SOURCE_TYPE = type;
		return ParseUtil.toObject(type+"");
	}
	/**
	 * 获取外部上报的预警信息
	 * author：mark   
	 * createTime：Dec 9, 2019 12:01:22 AM
	 * @param warninfo
	 * @return
	 */
	@RequestMapping(value = "/getInfo")
	@ResponseBody
	public Object getInfoFromClient(@RequestParam(value = "warninfo") String warninfo)
	{
		DataSourceAdapter.readFromClient(warninfo);
		return ParseUtil.toObject(warninfo);
	}
	/**
	 * 从数据仓库（数据库）获取预警流水
	 * author：mark   
	 * createTime：Dec 9, 2019 12:01:34 AM
	 * @return
	 */
	@RequestMapping(value = "/getWarnWater")
	@ResponseBody
	public Object getWarnWater()
	{
		String msg = "";
		if (Config.SOURCE_TYPE==0) {
			DataSourceAdapter.readFromStreams();
			msg=DBUtil.getWarnWater();
		}else {
			msg=DBUtil.getWarnWater();
		}
		//邮件报警功能
//		NotificationUtil.emailNoti(msg);
		if (Config.PRE_WARN.equals(msg)) {//没有更新
			msg = "0,0,0,0,0,0";
		}
		return ParseUtil.toObject(msg);
		
	}
	
	
}
